home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 November / Macworld Nov ’95.toast / Developers / Selection ƒ 2.5 / menulist < prev    next >
Encoding:
Text File  |  1994-11-06  |  1.1 KB  |  55 lines  |  [TEXT/MSET]

  1. (*
  2. Our menList object, MenuList, is intended to be used when making new menus
  3. that are not resource based.  Sending the id: message will obtain a number
  4. that is usable as a menu ID, that is, it will be a positive int, non-zero,
  5. and not already in use.
  6.  
  7. *)
  8.  
  9.  
  10. :class menList super{ handle }
  11.     int try
  12.  
  13. private
  14.  
  15. :m new:
  16.     $ a1c @ put: super ;m
  17.     
  18. :m count:    ( -- n )
  19.     new: self
  20.     lock: super
  21.     ptr: super w@ 6 /  \ see IM I-346
  22.     unlock: super ;m
  23.  
  24. :m unique?: { mID \ result -- b }
  25.     true -> result
  26.     count: self 0
  27.     lock: super
  28.     ?DO
  29.         ptr: super 6 +    \ offset to start of 6 bytes of info for first menu
  30.         I 6 * +            \ offset to Menu handle for next menu
  31.         @                \ the Menu handle
  32.         @ w@ mID = IF false -> result leave THEN
  33.     LOOP
  34.     unlock: super
  35.     result ;m
  36.  
  37. :m getTry: ( -- n )    \ n will be a non-zero int greater than 256
  38.     BEGIN
  39.         32000 random put: try
  40.         get: try 1 256 within? not nip 
  41.     UNTIL get: try
  42.     ;m
  43.  
  44. public
  45.  
  46. :m id:    ( --  n )    \ Will return a number suitable for use as a menu ID.
  47.                     \ It will assure a unique number.
  48.     BEGIN
  49.         getTry: self  unique?: self
  50.     UNTIL get: try ;m
  51.  
  52. ;class
  53.  
  54. menList menuList
  55.